home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / GraphicViewers / pCD / Source / hpcdtoppm.0.4 / main.c.ORIG < prev    next >
Text File  |  1993-03-23  |  18KB  |  790 lines

  1. /* hpcdtoppm (Hadmut's pcdtoppm) v0.4
  2. *  Copyright (c) 1992, 1993 by Hadmut Danisch (danisch@ira.uka.de).
  3. *  Permission to use and distribute this software and its
  4. *  documentation for noncommercial use and without fee is hereby granted,
  5. *  provided that the above copyright notice appear in all copies and that
  6. *  both that copyright notice and this permission notice appear in
  7. *  supporting documentation. It is not allowed to sell this software in 
  8. *  any way. This software is not public domain.
  9. */
  10.  
  11. #include "hpcdtoppm.h"
  12.  
  13. FILE  *fin=0,*fout=0;
  14.  
  15. uBYTE sbuffer[SECSIZE];
  16.  
  17. enum TURNS  turn     = T_UNSPEC;
  18. enum SIZES  size     = S_UNSPEC;
  19. enum OUTFOR outfor   = O_UNSPEC;
  20. enum CORR   corrmode = C_UNSPEC;
  21.  
  22. int do_info,do_diff,do_overskip,do_sharp,monochrome;
  23. int do_melde,do_rep,do_crop;
  24. int flhori=0,flvert=0;
  25. char *pcdname=0,*ppmname=0;
  26.  
  27.  
  28.  
  29. static implane Luma, Chroma1,Chroma2;
  30. static implane *PLuma,*PChroma1,*PChroma2;
  31. static int contsize=1;
  32.  
  33. static int print_pos;
  34. #define PrintPos(x) {if(print_pos) fprintf(stderr,"File-Offset: %8d = %8x (hex)\n",(x),(x));}
  35.  
  36. static void checkin();
  37. static void parseargs();
  38. static void f_1();
  39. static void f_3();
  40. static void f_4();
  41. static void f_5();
  42. static void f_ov();
  43. static void f_co();
  44.  
  45.  
  46.  
  47. void close_all()
  48.  {
  49.   if(fin) fclose(fin);
  50.   if(fout && ppmname) fclose(fout);
  51.  
  52.  }
  53.  
  54.  
  55. void main(argc,argv)
  56.   int argc;
  57.   char **argv;
  58.  {
  59.   do_info=do_diff=do_overskip=do_sharp=monochrome=0;
  60.   do_melde=do_rep=do_crop=0;
  61.   print_pos=0;
  62.  
  63.   parseargs(argc,argv);
  64.  
  65.   if(size     == S_UNSPEC) size     = S_DEFAULT;
  66.   if(outfor   == O_UNSPEC) outfor   = O_DEFAULT;
  67.   if(corrmode == C_UNSPEC) corrmode = C_DEFAULT;
  68.   if(turn     == T_UNSPEC) turn     = T_DEFAULT;
  69.  
  70.   monochrome=(outfor==O_PGM)||(outfor==O_PSG)||(outfor==O_EPSG);
  71.  
  72.  
  73.  
  74.  
  75.   if((size==S_Over) && (!ppmname)) error(E_ARG);
  76.   if((size==S_Contact) && do_crop) error(E_ARG);
  77.   if(do_overskip && do_diff) error(E_OPT);
  78.  
  79.   if(do_diff && (size != S_4Base) && (size != S_16Base)) error(E_OPT);
  80.  
  81.   if(do_overskip && (size != S_Base16) && (size != S_Base4) && (size != S_Base) && (size != S_4Base) ) error(E_OVSKIP);
  82.   if(print_pos   && (size != S_Base16) && (size != S_Base4) && (size != S_Base) && (size != S_4Base) ) error(E_OPT);
  83.   if(do_info     && (size != S_Base16) && (size != S_Base4) && (size != S_Base) && (size != S_4Base) ) error(E_OPT);
  84.   if(monochrome && do_overskip) error(E_OPT);
  85.   if((size==S_Contact) &&((contsize<1) || (contsize>100))) error(E_OPT);
  86.  
  87.   if(!(fin=fopen(pcdname,R_OP))) error(E_READ);
  88.  
  89.  
  90.  
  91.   if((size != S_Over) && (size != S_Contact)) checkin();
  92.  
  93.   PLuma=    &Luma;
  94.   PChroma1= monochrome ? 0 : &Chroma1; 
  95.   PChroma2= monochrome ? 0 : &Chroma2; 
  96.  
  97.   switch(size)
  98.    {
  99.     case S_Base16:  f_1(BaseW/4,BaseH/4,L_Head,(L_Head+L_Base16));
  100.                     break;
  101.  
  102.     case S_Base4:   f_1(BaseW/2,BaseH/2,(L_Head+L_Base16),(L_Head+L_Base16+L_Base4));
  103.                     break;
  104.  
  105.     case S_Base:    f_3(BaseW,BaseH,(L_Head+L_Base16+L_Base4));
  106.                     break;
  107.  
  108.     case S_4Base:   f_4(BaseW*2,BaseH*2,(L_Head+L_Base16+L_Base4));
  109.                     break;
  110.  
  111.     case S_16Base:  f_5(BaseW*4,BaseH*4);
  112.                     break;
  113.  
  114.     case S_Over:    f_ov(BaseW/4,BaseH/4,5,SeBase16);
  115.                     break;
  116.  
  117.     case S_Contact: f_co(BaseW/4,BaseH/4,5,SeBase16);
  118.                     break;
  119.  
  120.     default: error(E_INTERN); 
  121.    }
  122.  
  123.   close_all();
  124.   exit(0);
  125.  
  126.  }
  127.  
  128.  
  129.  
  130.  
  131.  
  132. static void f_1(w,h,normal,overskip)
  133.   dim w,h;
  134.   int normal,overskip;
  135.  {
  136.   planealloc(PLuma   ,w,h);
  137.   if (!monochrome) planealloc(PChroma1,w,h);
  138.   if (!monochrome) planealloc(PChroma2,w,h);
  139.  
  140.   PrintPos(normal*SECSIZE);
  141.   SEEK(normal+1);                   
  142.       
  143.   if(!do_overskip)
  144.     { error(readplain(fin,w,h,PLuma,PChroma1,PChroma2));
  145.       if (!monochrome) 
  146.         {interpolate(PChroma1);
  147.          interpolate(PChroma2);
  148.         }
  149.     }
  150.   else
  151.     { error(readplain(fin,w,h,PLuma,nullplane,nullplane));
  152.       SEEK(overskip+1);
  153.       error(readplain(fin,2*w,2*h,nullplane,PChroma1,PChroma2));
  154.     }
  155.    
  156.  
  157.   colconvert(&w,&h,PLuma,PChroma1,PChroma2);
  158.   /* Now Luma holds red, Chroma1 hold green, Chroma2 holds blue */
  159.  
  160.   if(!ppmname) fout=stdout;
  161.   else
  162.    {if (!(fout=fopen(ppmname,W_OP))) error(E_WRITE);
  163.    }
  164.   writepicture(w,h,PLuma,PChroma1,PChroma2,turn);
  165.  
  166.  } 
  167.  
  168.  
  169. static void f_3(w,h,normal)
  170.   dim w,h;
  171.   int normal;
  172.  {long cd_offset,cd_offhelp;
  173.  
  174.   PrintPos(normal*SECSIZE);
  175.   SEEK(normal+1);
  176.  
  177.   if(!do_overskip)
  178.     { planealloc(PLuma   ,w,h);
  179.       if (!monochrome) planealloc(PChroma1,w,h);
  180.       if (!monochrome) planealloc(PChroma2,w,h);
  181.       error(readplain(fin,w,h,PLuma,PChroma1,PChroma2));
  182.       if (!monochrome) 
  183.         {interpolate(PChroma1);
  184.          interpolate(PChroma2);
  185.         }
  186.     }
  187.   else
  188.     { planealloc(PLuma   ,  w,  h);
  189.       if (!monochrome) planealloc(PChroma1,2*w,2*h);
  190.       if (!monochrome) planealloc(PChroma2,2*w,2*h);
  191.       error(readplain(fin,w,h,PLuma,PChroma1,PChroma2));
  192.       interpolate(PChroma1);
  193.       interpolate(PChroma2);
  194.       interpolate(PChroma1);
  195.       interpolate(PChroma2);
  196.  
  197.       cd_offset=Skip4Base();
  198.       SEEK(cd_offset+10);          EREADBUF;    cd_offhelp=(((long)sbuffer[2])<<8)|sbuffer[3];
  199.       SEEK(cd_offset+12);          readhqt(w,h,3);
  200.       SEEK(cd_offset+cd_offhelp);  decode(4*w,4*h,nullplane,PChroma1,PChroma2,1);
  201.  
  202.       halve(PChroma1);
  203.       halve(PChroma2);
  204.     }
  205.   colconvert(&w,&h,PLuma,PChroma1,PChroma2);
  206.   /* Now Luma holds red, Chroma1 hold green, Chroma2 holds blue */
  207.  
  208.   if(!ppmname) fout=stdout;
  209.   else
  210.    {if (!(fout=fopen(ppmname,W_OP))) error(E_WRITE);
  211.    }
  212.   writepicture(w,h,PLuma,PChroma1,PChroma2,turn);
  213.  
  214.  
  215.  }
  216.  
  217.  
  218.  
  219. static void f_4(w,h,normal)
  220.   dim w,h;
  221.   int normal;
  222.  {long cd_offset,cd_offhelp;
  223.  
  224.   planealloc(PLuma,w,h);
  225.   if (!monochrome) planealloc(PChroma1,w,h);
  226.   if (!monochrome) planealloc(PChroma2,w,h);
  227.   PrintPos((L_Head+L_Base16+L_Base4+L_Base)*SECSIZE);
  228.  
  229.   if(!do_overskip)
  230.    {SEEK(L_Head+L_Base16+L_Base4+1);
  231.     error(readplain(fin,w/2,h/2,PLuma,PChroma1,PChroma2));
  232.     interpolate(PLuma);
  233.     if (!monochrome) 
  234.      {interpolate(PChroma1);
  235.       interpolate(PChroma1);
  236.       interpolate(PChroma2);
  237.       interpolate(PChroma2);
  238.      }
  239.  
  240.     if(do_diff) {clear(PLuma,neutrLum);clear(PChroma1,neutrCh1);clear(PChroma2,neutrCh2);}
  241.  
  242.     cd_offset = L_Head + L_Base16 + L_Base4 + L_Base ;
  243.     SEEK(cd_offset + 4);     readhqt(w,h,1);
  244.     SEEK(cd_offset + 5);     decode(w,h,PLuma,nullplane,nullplane,0);
  245.    }
  246.   else
  247.    {SEEK(L_Head+L_Base16+L_Base4+1);
  248.     error(readplain(fin,w/2,h/2,PLuma,PChroma1,PChroma2));
  249.     interpolate(PLuma);
  250.     interpolate(PChroma1);
  251.     interpolate(PChroma1);
  252.     interpolate(PChroma2);
  253.     interpolate(PChroma2);
  254.  
  255.     cd_offset = L_Head + L_Base16 + L_Base4 + L_Base ;
  256.     SEEK(cd_offset + 4);     readhqt(w,h,1);
  257.     SEEK(cd_offset + 5);     decode(w,h,PLuma,nullplane,nullplane,0);
  258.  
  259.     cd_offset=ftell(fin);if(cd_offset % SECSIZE) error(E_POS);cd_offset/=SECSIZE;
  260.     SEEK(cd_offset+10);          EREADBUF;    cd_offhelp=(((long)sbuffer[2])<<8)|sbuffer[3];
  261.     SEEK(cd_offset+12);          readhqt(w,h,3);
  262.     SEEK(cd_offset+cd_offhelp);  decode(2*w,2*h,nullplane,PChroma1,PChroma2,1);
  263.      
  264.    }
  265.   colconvert(&w,&h,PLuma,PChroma1,PChroma2);
  266.   /* Now Luma holds red, Chroma1 hold green, Chroma2 holds blue */
  267.  
  268.   if(!ppmname) fout=stdout;
  269.   else
  270.    {if (!(fout=fopen(ppmname,W_OP))) error(E_WRITE);
  271.    }
  272.   writepicture(w,h,PLuma,PChroma1,PChroma2,turn);
  273.  
  274.  }
  275.  
  276.  
  277.  
  278. static void f_5(w,h)
  279.   dim w,h;
  280.  {long cd_offset;
  281.  
  282.   planealloc(PLuma,w,h);
  283.   if (!monochrome) planealloc(PChroma1,w,h);
  284.   if (!monochrome) planealloc(PChroma2,w,h);
  285.  
  286.   SEEK(L_Head+L_Base16+L_Base4+1);
  287.   error(readplain(fin,w/4,h/4,PLuma,PChroma1,PChroma2));
  288.   interpolate(PLuma);
  289.   if(!monochrome)
  290.    {interpolate(PChroma1);
  291.     interpolate(PChroma1);
  292.     interpolate(PChroma2);
  293.     interpolate(PChroma2);
  294.    }
  295.  
  296.   cd_offset = L_Head + L_Base16 + L_Base4 + L_Base ;
  297.   SEEK(cd_offset + 4);       readhqt(w/2,h/2,1);
  298.   SEEK(cd_offset + 5);       decode(w/2,h/2,PLuma,nullplane,nullplane,0);
  299.   interpolate(PLuma);
  300.  
  301.   if(do_diff) {clear(PLuma,neutrLum);clear(PChroma1,neutrCh1);clear(PChroma2,neutrCh2);}
  302.  
  303.   cd_offset=ftell(fin);
  304.   if(cd_offset % SECSIZE) error(E_POS);
  305.   PrintPos(cd_offset);
  306.   cd_offset/=SECSIZE;
  307.  
  308.   SEEK(cd_offset+12);        readhqt(w,h,3);
  309.   SEEK(cd_offset+14);        decode(w,h,PLuma,PChroma1,PChroma2,0);
  310.  
  311.   if(!monochrome)
  312.    {interpolate(PChroma1);
  313.     interpolate(PChroma2);
  314.    }
  315.  
  316.   colconvert(&w,&h,PLuma,PChroma1,PChroma2);
  317.   /* Now Luma holds red, Chroma1 hold green, Chroma2 holds blue */
  318.  
  319.   if(!ppmname) fout=stdout;
  320.   else
  321.    {if (!(fout=fopen(ppmname,W_OP))) error(E_WRITE);
  322.    }
  323.   writepicture(w,h,PLuma,PChroma1,PChroma2,turn);
  324.  
  325.  }
  326.  
  327.  
  328.  
  329.  
  330. static void f_ov(w,h,offset,imsize)
  331.   dim w,h;
  332.   int offset,imsize;
  333.  {int bildnr,bilder;
  334.   dim wx,hx;
  335.   enum ERRORS eret;
  336.   enum TURNS imorient;
  337.   char nbuf[100];
  338.  
  339.   wx=w; hx=h;
  340.  
  341.   planealloc(PLuma   ,w,h);
  342.   if (!monochrome) planealloc(PChroma1,w,h);
  343.   if (!monochrome) planealloc(PChroma2,w,h);
  344.  
  345.   SEEK(0); READBUF;
  346.   bilder=(((int) sbuffer[10])<<8) | sbuffer[11];
  347.  
  348.  
  349.   for(bildnr=0;bildnr<bilder;bildnr++)
  350.    {
  351.     w=wx;h=hx;
  352.     PLuma->im=PLuma->mp;
  353.     if(PChroma1) PChroma1->im=PChroma1->mp;
  354.     if(PChroma2) PChroma2->im=PChroma2->mp;
  355.  
  356.     SEEK(offset+imsize*bildnr);
  357.   
  358.     eret=readplain(fin,w,h,PLuma,PChroma1,PChroma2);
  359.     if(eret==E_READ) break;
  360.     error(eret);
  361.  
  362.     if(!monochrome)
  363.      {interpolate(PChroma1);
  364.       interpolate(PChroma2);
  365.      }
  366.  
  367.     colconvert(&w,&h,PLuma,PChroma1,PChroma2);
  368.   
  369.     sprintf(nbuf,"%s%04d",ppmname,bildnr+1);
  370.     if (!(fout=fopen(nbuf,W_OP))) error(E_WRITE);
  371.      switch(sbuffer[12+bildnr] & 3)
  372.       {case 0:  imorient=T_NONE; break;
  373.        case 1:  imorient=T_LEFT; break;
  374.        case 3:  imorient=T_RIGHT; break;
  375.        default: imorient=T_NONE;
  376.       }
  377.     writepicture(w,h,PLuma,PChroma1,PChroma2,turn != T_AUTO ? turn : imorient);
  378.    }
  379.  }
  380.  
  381.  
  382.  
  383.  
  384. static void f_co(w,h,offset,imsize)
  385.   dim w,h;
  386.   int offset,imsize;
  387.  {int bildnr,bilder,cols,rows,xstep,ystep,mw,mh;
  388.   enum ERRORS eret;
  389.   enum TURNS imorient;
  390.   implane mLuma,mChroma1,mChroma2;
  391.   implane *pmL,*pmCh1,*pmCh2;
  392.  
  393.   pmL=    &mLuma;
  394.   pmCh1= monochrome ? 0 : &mChroma1; 
  395.   pmCh2= monochrome ? 0 : &mChroma2; 
  396.  
  397.  
  398.   SEEK(0); READBUF;
  399.   bilder=(((int) sbuffer[10])<<8) | sbuffer[11];
  400.  
  401.   cols=contsize;
  402.   rows=(bilder+cols-1)/cols;
  403.  
  404.   xstep=ystep=0;
  405.  
  406.   switch(turn)
  407.    {case T_NONE: xstep=w;ystep=h; break;
  408.     case T_RIGHT:
  409.     case T_LEFT: xstep=h;ystep=w; break;
  410.     case T_AUTO: xstep=ystep=w;   break;
  411.     default: error(E_INTERN);
  412.    }
  413.  
  414.   mw=cols*xstep;
  415.   mh=rows*ystep;
  416.  
  417.   planealloc(PLuma   ,w,h);
  418.   if (!monochrome) planealloc(PChroma1,w,h);
  419.   if (!monochrome) planealloc(PChroma2,w,h);
  420.  
  421.   planealloc(pmL,mw,mh);
  422.   mLuma.iwidth=mw;
  423.   mLuma.iheight=mh;
  424.   clear(pmL,CONTLUM);
  425.  
  426.   if(!monochrome)
  427.    { planealloc(pmCh1,mw,mh);
  428.      mChroma1.iwidth=mw;
  429.      mChroma1.iheight=mh;
  430.      clear(pmCh1,CONTCH1);
  431.  
  432.      planealloc(pmCh2,mw,mh);
  433.      mChroma2.iwidth=mw;
  434.      mChroma2.iheight=mh;
  435.      clear(pmCh2,CONTCH2);
  436.    }
  437.  
  438.  
  439.   for(bildnr=0;bildnr<bilder;bildnr++)
  440.    {
  441.     SEEK(offset+imsize*bildnr);
  442.   
  443.     eret=readplain(fin,w,h,PLuma,PChroma1,PChroma2);
  444.     if(eret==E_READ) break;
  445.     error(eret);
  446.  
  447.     if(!monochrome)
  448.      {interpolate(PChroma1);
  449.       interpolate(PChroma2);
  450.      }
  451.  
  452.     switch(sbuffer[12+bildnr] & 3)
  453.      {case 0:  imorient=T_NONE; break;
  454.       case 1:  imorient=T_LEFT; break;
  455.       case 3:  imorient=T_RIGHT; break;
  456.       default: imorient=T_NONE;
  457.      }
  458.     pastein(pmL,(bildnr%cols)*xstep,xstep,(bildnr/cols)*ystep,ystep,PLuma,((turn==T_AUTO)? imorient:turn));
  459.     if(!monochrome)
  460.      {pastein(pmCh1,(bildnr%cols)*xstep,xstep,(bildnr/cols)*ystep,ystep,PChroma1,((turn==T_AUTO)? imorient:turn));
  461.       pastein(pmCh2,(bildnr%cols)*xstep,xstep,(bildnr/cols)*ystep,ystep,PChroma2,((turn==T_AUTO)? imorient:turn));
  462.      }
  463.    }
  464.  
  465.   colconvert(&mw,&mh,pmL,pmCh1,pmCh2);
  466.  
  467.   if(!ppmname) fout=stdout;
  468.   else
  469.    {if (!(fout=fopen(ppmname,W_OP))) error(E_WRITE);
  470.    }
  471.   writepicture(mw,mh,pmL,pmCh1,pmCh2,CONTORI);
  472.  
  473.  }
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482. #define ASKIP { argc--; argv ++;}
  483.  
  484. static void parseargs(argc,argv)
  485.   int argc;
  486.   char **argv;
  487.  {
  488.   char *opt;
  489.  
  490.   ASKIP;
  491.  
  492.   while((argc>0) && **argv=='-')
  493.    {
  494.     opt= (*argv)+1;
  495.     ASKIP;
  496.  
  497. /**** additional options ****/
  498.  
  499.     if(!strcmp(opt,"x")) 
  500.      { if (!do_overskip) do_overskip=1;
  501.        else error(E_ARG);
  502.        continue;
  503.      }
  504.  
  505.     if(!strcmp(opt,"s")) 
  506.      { if (!do_sharp) do_sharp=1;
  507.        else error(E_ARG);
  508.        continue;
  509.      }
  510.  
  511.     if(!strcmp(opt,"d")) 
  512.      { if (!do_diff) do_diff=1;
  513.        else error(E_ARG);
  514.        continue;
  515.      }
  516.  
  517.     if(!strcmp(opt,"i")) 
  518.      { if (!do_info) do_info=1;
  519.        else error(E_ARG);
  520.        continue;
  521.      }
  522.  
  523.  
  524.     if(!strcmp(opt,"m")) 
  525.      { if (!do_melde) do_melde=1;
  526.        else error(E_ARG);
  527.        continue;
  528.      }
  529.  
  530.     if(!strcmp(opt,"crop")) 
  531.      { if (!do_crop) do_crop=1;
  532.        else error(E_ARG);
  533.        continue;
  534.      }
  535.  
  536.     if(!strcmp(opt,"pos")) 
  537.      { if (!print_pos) print_pos=1;
  538.        else error(E_ARG);
  539.        continue;
  540.      }
  541.  
  542.     if(!strcmp(opt,"rep")) 
  543.      { if (!do_rep) do_rep=1;
  544.        else error(E_ARG);
  545.        continue;
  546.      }
  547.  
  548. /****  Orientation options ****/
  549.  
  550.     if(!strcmp(opt,"n"))
  551.      {if (turn == T_UNSPEC) turn=T_NONE;
  552.       else error(E_ARG);
  553.       continue;
  554.      }
  555.  
  556.     if(!strcmp(opt,"r"))
  557.      {if (turn == T_UNSPEC) turn=T_RIGHT;
  558.       else error(E_ARG);
  559.       continue;
  560.      }
  561.  
  562.     if(!strcmp(opt,"l"))
  563.      {if (turn == T_UNSPEC) turn=T_LEFT;
  564.       else error(E_ARG);
  565.       continue;
  566.      }
  567.  
  568.     if(!strcmp(opt,"a"))
  569.      {if (turn == T_UNSPEC) turn=T_AUTO;
  570.       else error(E_ARG);
  571.       continue;
  572.      }
  573.  
  574.     if(!strcmp(opt,"vert"))
  575.      {if (!flvert) flvert=1;
  576.       else error(E_ARG);
  577.       continue;
  578.      }
  579.  
  580.     if(!strcmp(opt,"hori"))
  581.      {if (!flhori) flhori=1;
  582.       else error(E_ARG);
  583.       continue;
  584.      }
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591. /**** Output options ****/
  592.  
  593.  
  594.     if((!strcmp(opt,"ppm")) || (!strcmp(opt,"PPM")))
  595.      { if (outfor == O_UNSPEC) outfor=O_PPM;
  596.        else error(E_ARG);
  597.        continue;
  598.      }
  599.  
  600.     if((!strcmp(opt,"pgm")) || (!strcmp(opt,"PGM")))
  601.      { if (outfor == O_UNSPEC) outfor=O_PGM;
  602.        else error(E_ARG);
  603.        continue;
  604.      }
  605.  
  606.     if(!strcmp(opt,"ycc")) 
  607.      { if (outfor == O_UNSPEC) outfor=O_YCC;
  608.        else error(E_ARG);
  609.        continue;
  610.      }
  611.  
  612.     if((!strcmp(opt,"ps")) || (!strcmp(opt,"PS")))
  613.      { if (outfor == O_UNSPEC) outfor=O_PS;
  614.        else error(E_ARG);
  615.        continue;
  616.      }
  617.  
  618.     if((!strcmp(opt,"eps")) || (!strcmp(opt,"EPS")))
  619.      { if (outfor == O_UNSPEC) outfor=O_EPS;
  620.        else error(E_ARG);
  621.        continue;
  622.      }
  623.  
  624.     if((!strcmp(opt,"psg")) || (!strcmp(opt,"PSG")))
  625.      { if (outfor == O_UNSPEC) outfor=O_PSG;
  626.        else error(E_ARG);
  627.        continue;
  628.      }
  629.  
  630.     if((!strcmp(opt,"epsg")) || (!strcmp(opt,"EPSG")))
  631.      { if (outfor == O_UNSPEC) outfor=O_EPSG;
  632.        else error(E_ARG);
  633.        continue;
  634.      }
  635.  
  636.  
  637.  
  638.  
  639.  
  640.     if(!strcmp(opt,"pl" ))
  641.      { if(argc<1) error(E_ARG);
  642.        if((sscanf(*argv,"%f",&PAPER_LEFT))!=1) error(E_ARG);
  643.        ASKIP;
  644.        continue;
  645.      }
  646.  
  647.     if(!strcmp(opt,"pb" ))
  648.      { if(argc<1) error(E_ARG);
  649.        if((sscanf(*argv,"%f",&PAPER_BOTTOM))!=1) error(E_ARG);
  650.        ASKIP;
  651.        continue;
  652.      }
  653.  
  654.  
  655.     if(!strcmp(opt,"pw" ))
  656.      { if(argc<1) error(E_ARG);
  657.        if((sscanf(*argv,"%f",&PAPER_WIDTH))!=1) error(E_ARG);
  658.        ASKIP;
  659.        continue;
  660.      }
  661.  
  662.     if(!strcmp(opt,"ph" ))
  663.      { if(argc<1) error(E_ARG);
  664.        if((sscanf(*argv,"%f",&PAPER_HEIGHT))!=1) error(E_ARG);
  665.        ASKIP;
  666.        continue;
  667.      }
  668.  
  669. /**** Color model options ****/
  670.  
  671.     if(!strcmp(opt,"c0")) 
  672.      { if (corrmode == C_UNSPEC) corrmode = C_LINEAR;
  673.        else error(E_ARG);
  674.        continue;
  675.      }
  676.  
  677.     if(!strcmp(opt,"c-")) 
  678.      { if (corrmode == C_UNSPEC) corrmode = C_DARK;
  679.        else error(E_ARG);
  680.        continue;
  681.      }
  682.  
  683.     if(!strcmp(opt,"c+")) 
  684.      { if (corrmode == C_UNSPEC) corrmode = C_BRIGHT;
  685.        else error(E_ARG);
  686.        continue;
  687.      }
  688.  
  689.    
  690.  
  691.  
  692.  
  693. /**** Resolution options ****/
  694.    
  695.     if((!strcmp(opt,"Base/16")) || (!strcmp(opt,"1"))  || (!strcmp(opt,"128x192")))
  696.      { if (size == S_UNSPEC) size = S_Base16;
  697.        else error(E_ARG);
  698.        continue;
  699.      }
  700.     if((!strcmp(opt,"Base/4" )) || (!strcmp(opt,"2"))  || (!strcmp(opt,"256x384")))
  701.      { if (size == S_UNSPEC) size = S_Base4;
  702.        else error(E_ARG);
  703.        continue;
  704.      }
  705.     if((!strcmp(opt,"Base"   )) || (!strcmp(opt,"3"))  || (!strcmp(opt,"512x768")))
  706.      { if (size == S_UNSPEC) size = S_Base;
  707.        else error(E_ARG);
  708.        continue;
  709.      }
  710.     if((!strcmp(opt,"4Base"  )) || (!strcmp(opt,"4"))  || (!strcmp(opt,"1024x1536")))
  711.      { if (size == S_UNSPEC) size = S_4Base;
  712.        else error(E_ARG);
  713.        continue;
  714.      }
  715.     if((!strcmp(opt,"16Base" )) || (!strcmp(opt,"5"))  || (!strcmp(opt,"2048x3072")))
  716.      { if (size == S_UNSPEC) size = S_16Base;
  717.        else error(E_ARG);
  718.        continue;
  719.      }
  720.  
  721.     if((!strcmp(opt,"Overview" )) || (!strcmp(opt,"0"))  || (!strcmp(opt,"O")))
  722.      { if (size == S_UNSPEC) size = S_Over;
  723.        else error(E_ARG);
  724.        continue;
  725.      }
  726.  
  727.     if((!strcmp(opt,"Contact" )) || (!strcmp(opt,"C")))
  728.      { if (size == S_UNSPEC) size = S_Contact;
  729.        else error(E_ARG);
  730.        if(argc<1) error(E_ARG);
  731.        if((sscanf(*argv,"%d",&contsize))!=1) error(E_ARG);
  732.        ASKIP;
  733.        continue;
  734.      }
  735.  
  736.    fprintf(stderr,"Unknown option: -%s\n",opt);
  737.    error(E_ARG);
  738.    }
  739.  
  740.   
  741.   if(argc<1) error(E_ARG);
  742.   pcdname= *argv;
  743.   ASKIP;
  744.  
  745.   if(argc>0) 
  746.    {ppmname= *argv;
  747.     ASKIP;
  748.    }
  749.   
  750.   if(argc>0) error(E_ARG);
  751.  
  752.  
  753.  }
  754. #undef ASKIP
  755.  
  756.  
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765. void checkin()
  766.  { 
  767.    if (do_info || (turn==T_AUTO)) 
  768.      { SEEK(1);
  769.        EREADBUF;
  770.      }
  771.  
  772.     if(turn==T_AUTO) 
  773.      {
  774.       switch(sbuffer[0xe02 & 0x7ff]&0x03)
  775.        {case 0x00: turn=T_NONE;  break;
  776.         case 0x01: turn=T_LEFT;  break;
  777.         case 0x03: turn=T_RIGHT; break;
  778.         default: error(E_TCANT);
  779.        }
  780.       }
  781.  
  782.     if(do_info) druckeid();
  783.  
  784.  }
  785.  
  786.  
  787.  
  788.  
  789.  
  790.